package com.ssy.lingxi.contract.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.contract.model.vo.common.request.ContractInnerRecordPageVO;
import com.ssy.lingxi.contract.model.vo.common.request.ContractOuterRecordPageVO;
import com.ssy.lingxi.contract.model.vo.common.request.PurchaseMaterielPageVO;
import com.ssy.lingxi.contract.model.vo.common.response.ContractOuterRecordVO;
import com.ssy.lingxi.contract.model.vo.common.response.PageItemVO;
import com.ssy.lingxi.contract.model.vo.common.response.PurchaseMaterielQueryVO;
import com.ssy.lingxi.contract.model.vo.common.response.StatusVO;
import com.ssy.lingxi.contract.model.vo.manage.request.*;
import com.ssy.lingxi.contract.model.vo.manage.response.*;
import com.ssy.lingxi.contract.service.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 合同能力-合同管理
 * @author 伍将
 * @date 2021/02/02
 * @version 2.0.0
 */
@RestController
@RequestMapping("/contract/manage")
public class ContractManageController extends BaseController {

    @Resource
    private IContractManageService contractManageService;

    @Resource
    private IContractPurchaseMaterielService purchaseMaterielService;

    @Resource
    private IContractOuterRecordService outerRecordService;

    @Resource
    private IContractInnerRecordService innerRecordService;
    @Resource
    private IStatusService statusService;

    /**
     * 合同查询-分页查询合同
     * @author 伍将
     * @date 2021/2/2
     **/
    @RequestMapping(value = "/pageList", method = RequestMethod.GET)
    public Wrapper<PageData<ContractManageQueryVO>> pageList(HttpServletRequest httpRequest, @Valid ContractManagePageVO pageVO) {
        return contractManageService.pageList(getSysUser(httpRequest), pageVO);
    }

    /**
     * 合同查询-分页查询合同-作废合同
     * @author 伍将
     * @date 2021/2/25
     **/
    @RequestMapping("/invalid")
    public Wrapper<Void> invalid(HttpServletRequest httpRequest, @RequestBody @Valid ContractManageInvalidVO saveVO) {
        return contractManageService.invalid(getSysUser(httpRequest), saveVO);
    }

    /**
     * 查询合同详情
     * @author 伍将
     * @date 2021/2/8
     **/
    @RequestMapping(value = "/getDetail", method = RequestMethod.GET)
    public Wrapper<ContractManageDetailVO> getDetail(HttpServletRequest httpRequest, Long contractId) {
        return contractManageService.getDetail(getSysUser(httpRequest), contractId);
    }

    /**
     * 查询合同详情-分页查询合同外部流转记录
     * @author 伍将
     * @date 2021/2/24
     **/
    @RequestMapping(value = "/pageOuterRecordList", method = RequestMethod.GET)
    public Wrapper<PageData<ContractOuterRecordVO>> pageOuterRecordList(HttpServletRequest httpRequest, @Valid ContractOuterRecordPageVO pageVO) {
        getSysUser(httpRequest);
        return outerRecordService.pageList(pageVO);
    }

    /**
     * 查询合同详情-分页查询合同内部流转记录
     * @author 伍将
     * @date 2021/2/24
     **/
    @RequestMapping(value = "/pageInnerRecordList", method = RequestMethod.GET)
    public Wrapper<PageData<ContractManageInnerRecordVO>> pageInnerRecordList(HttpServletRequest httpRequest, @Valid ContractInnerRecordPageVO pageVO) {
        return innerRecordService.pageManageList(getSysUser(httpRequest), pageVO);
    }

    /**
     * 查询合同详情-分页查询合同采购物料
     * @author 伍将
     * @date 2021/2/8
     **/
    @RequestMapping(value = "/pagePurchaseMaterielList", method = RequestMethod.GET)
    public Wrapper<PageData<PurchaseMaterielQueryVO>> pagePurchaseMaterielList(HttpServletRequest httpRequest, @Valid PurchaseMaterielPageVO pageVO) {
        return purchaseMaterielService.pageList(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待新增合同-分页查询待新增合同
     * @author 伍将
     * @date 2021/2/3
     **/
    @RequestMapping(value = "/pageToBeAdd", method = RequestMethod.GET)
    public Wrapper<PageData<ContractManageQueryVO>> pageToBeAdd(HttpServletRequest httpRequest, @Valid ContractManageCommonPageVO pageVO) {
        return contractManageService.pageToBeAdd(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待新增合同-获取合同编号
     * @author 伍将
     * @date 2021/3/26
     **/
    @RequestMapping(value = "/getContractNo", method = RequestMethod.GET)
    public Wrapper<String> getContractNo(String oldContractNo) {
        return contractManageService.getContractNo(oldContractNo);
    }

    /**
     * 待新增合同-保存合同
     * @author 伍将
     * @date 2021/2/25
     **/
    @RequestMapping("/save")
    public Wrapper<Long> save(HttpServletRequest httpRequest, @RequestBody @Valid ContractUpdateVO saveVO) {
        return contractManageService.save(getSysUser(httpRequest), saveVO);
    }

    /**
     * 待新增合同-提交
     * @author 伍将
     * @date 2021/2/3
     **/
    @RequestMapping("/submit")
    public Wrapper<Void> submit(HttpServletRequest httpRequest, @RequestBody @Valid ContractManageSubmitVO submitVO) {
        return contractManageService.submit(getSysUser(httpRequest), submitVO);
    }

    /**
     * 待新增合同-删除
     * @author 伍将
     * @date 2021/2/3
     **/
    @RequestMapping("/delete")
    public Wrapper<Void> delete(HttpServletRequest httpRequest, @RequestBody @Valid ContractManageDeleteVO deleteVO) {
        return contractManageService.delete(getSysUser(httpRequest), deleteVO);
    }

    /**
     * 待提交审核合同-分页查询待提交审核合同
     * @author 伍将
     * @date 2021/2/2
     **/
    @RequestMapping(value = "/pageToBeSubmitExamine", method = RequestMethod.GET)
    public Wrapper<PageData<ContractManageQueryVO>> pageToBeSubmitExamine(HttpServletRequest httpRequest, @Valid ContractManageCommonPageVO pageVO) {
        return contractManageService.pageToBeSubmitExamine(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待提交审核合同-提交审核
     * @author 伍将
     * @date 2021/2/3
     **/
    @RequestMapping("/submitExamine")
    public Wrapper<Void> submitExamine(HttpServletRequest httpRequest, @RequestBody @Valid ContractManageExamineVO examineVO) {
        return contractManageService.submitExamine(getSysUser(httpRequest), examineVO);
    }

    /**
     * 待审核合同(一级)-分页查询待审核合同
     * @author 伍将
     * @date 2021/2/2
     **/
    @RequestMapping(value = "/pageToBeExamineStepOne", method = RequestMethod.GET)
    public Wrapper<PageData<ContractManageQueryVO>> pageToBeExamineStepOne(HttpServletRequest httpRequest, @Valid ContractManageCommonPageVO pageVO) {
        return contractManageService.pageToBeExamineStepOne(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待审核合同(一级)-审核合同
     * @author 伍将
     * @date 2021/2/3
     **/
    @RequestMapping("/examineStepOne")
    public Wrapper<Void> examineStepOne(HttpServletRequest httpRequest, @RequestBody @Valid ContractManageExamineVO examineVO) {
        return contractManageService.examineStepOne(getSysUser(httpRequest), examineVO);
    }

    /**
     * 待审核合同(二级)-分页查询待审核合同
     * @author 伍将
     * @date 2021/2/2
     **/
    @RequestMapping(value = "/pageToBeExamineStepTwo", method = RequestMethod.GET)
    public Wrapper<PageData<ContractManageQueryVO>> pageToBeExamineStepTwo(HttpServletRequest httpRequest, @Valid ContractManageCommonPageVO pageVO) {
        return contractManageService.pageToBeExamineStepTwo(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待审核合同(二级)-审核合同
     * @author 伍将
     * @date 2021/2/3
     **/
    @RequestMapping("/examineStepTwo")
    public Wrapper<Void> examineStepTwo(HttpServletRequest httpRequest, @RequestBody @Valid ContractManageExamineVO examineVO) {
        return contractManageService.examineStepTwo(getSysUser(httpRequest), examineVO);
    }

    /**
     * 待签订合同-分页查询待签订合同
     * @author 伍将
     * @date 2021/2/2
     **/
    @RequestMapping(value = "/pageToBeSign", method = RequestMethod.GET)
    public Wrapper<PageData<ContractManageQueryVO>> pageToBeSign(HttpServletRequest httpRequest, @Valid ContractManageCommonPageVO pageVO) {
        return contractManageService.pageToBeSign(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待签订合同-签订合同
     * @author 伍将
     * @date 2021/2/7
     **/
    @RequestMapping("/sign")
    public Wrapper<Void> sign(HttpServletRequest httpRequest, @RequestBody @Valid ContractManageExamineVO examineVO) {
        return contractManageService.sign(getSysUser(httpRequest), examineVO);
    }

    /**
     * 合同查询-查询外部状态列表
     * @author 伍将
     * @date 2021/2/2
     **/
    @RequestMapping(value = "/getOuterStatusList", method = RequestMethod.GET)
    public Wrapper<List<PageItemVO>> getOuterStatusList() {
        return contractManageService.getOuterStatusList();
    }

    /**
     * 合同查询-查询内部状态列表
     * @author 伍将
     * @date 2021/2/2
     **/
    @RequestMapping(value = "/getInnerStatusList", method = RequestMethod.GET)
    public Wrapper<List<PageItemVO>> getInnerStatusList() {
        return contractManageService.getInnerStatusList();
    }

    /**
     * 分页查询已完成合同
     * @author 伍将
     * @date 2021/2/2
     **/
    @RequestMapping(value = "/pageCompleteList", method = RequestMethod.GET)
    public Wrapper<PageData<ContractCompleteQueryVO>> pageCompleteList(HttpServletRequest httpRequest, @Valid ContractManageCommonPageVO pageVO) {
        return contractManageService.pageCompleteList(getSysUser(httpRequest), pageVO);
    }

    /**
     * 查询合同信息[收款方信息+付款计划]（新增请款单）
     * @param httpRequest
     * @param contractId
     * @return
     */
    @RequestMapping(value = "/getContractInfoByApplyAmountOrder", method = RequestMethod.GET)
    public Wrapper<ContractManageInfoVO> getContractInfoByApplyAmountOrder(HttpServletRequest httpRequest, @RequestParam("contractId") Long contractId) {
        return contractManageService.getContractInfo(getSysUser(httpRequest), contractId);
    }

    /**
     * 状态查询
     * @author ds
     * @date 2021/5/28
     **/
    @RequestMapping(value = "/status/list", method = RequestMethod.GET)
    public Wrapper<StatusVO> statusList(HttpServletRequest httpRequest) {
        return statusService.getStatusByContractManage();
    }
}
